package com.test.demos.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.stp.StpUtil;
import com.test.demos.pojo.dto.MedicalPackagesDTO;
import com.test.demos.pojo.entity.MedicalPackages;
import com.test.demos.service.MedicalPackagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.test.demos.utils.Result;

/**
 * 体检套餐
 *
 * @author twt
 * @since 2025-04-14 16:26:54
 */
@CrossOrigin
@RestController
@RequestMapping("medicalPackages")
public class MedicalPackagesController {

    /**
     * 服务对象
     */
    @Autowired
    private MedicalPackagesService medicalPackagesService;


    /**
     * 查询全部数据-简单VO
     *
     * @return 实例对象
     */
    @SaCheckLogin
    @GetMapping()
    public Result queryAll() {
        return Result.ok(medicalPackagesService.queryAll());
    }

    /**
     * 通过ID查询单条数据
     *
     * @param packageId 主键
     * @return 实例对象
     */
    @SaCheckLogin
    @GetMapping("{id}")
    public Result queryById(@PathVariable("id") Integer packageId) {
        return Result.ok(medicalPackagesService.queryById(packageId));
    }



    /**
     * 新增数据
     *
     * @param dto 实例对象
     * @return 实例对象
     */
    @SaCheckPermission(orRole = {"admin", "emp"})
    @PostMapping
    public Result add(@RequestBody MedicalPackagesDTO dto) {
        medicalPackagesService.add(dto);
        return Result.ok();
    }

    /**
     * 更新数据
     *
     * @param medicalPackages 实例对象
     */
    @PutMapping
    @SaCheckPermission(orRole = {"admin", "emp"})
    public Result update(@RequestBody MedicalPackages medicalPackages) {
        medicalPackagesService.update(medicalPackages);
        return Result.ok();
    }

    /**
     * 通过主键删除数据
     *
     * @param packageId 主键
     * @return 是否成功
     */
    @DeleteMapping("{id}")
    @SaCheckRole(value = {"admin", "emp"}, mode = SaMode.OR)
    public Result deleteById(@PathVariable("id") Integer packageId) {
        medicalPackagesService.deleteById(packageId);
        return Result.ok();
    }
}
